from django.contrib.auth import get_user_model

User = get_user_model()


class MyBackend(object):
    def authenticate(self, phone=None, password=None):
        try:
            user = User.objects.get(phone=phone)

            if user is not None:
                if user.check_password(password):
                    return user
                else:
                    return None
            else:
                return None
        except User.DoesNotExist:
            return None

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None
